using AndyPike.Commons.TestSupport;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using WatiN.Core;

namespace AndyPike.Snowflake.Web.Tests.Acceptance
{
    public class When_the_register_page_is_requested : AcceptanceTestBase
    {
        [Test, Category("Acceptance")]
        public void Should_display_the_register_controls()
        {
            using (var browser = new IE(BuildUrl("Account", "New")))
            {
                Assert.That(browser.TextField(Find.ById("registration_userName")).Exists, Is.True);
                Assert.That(browser.TextField(Find.ById("registration_password")).Exists, Is.True);
                Assert.That(browser.TextField(Find.ById("registration_email")).Exists, Is.True);
                Assert.That(browser.TextField(Find.ById("recaptcha_response_field")).Exists, Is.True);
                Assert.That(browser.Button(Find.ById("register")).Exists, Is.True);
            }
        }

        [Test, Category("Acceptance")]
        public void Should_display_an_error_message_when_the_captcha_challenge_is_failed()
        {
            using (var browser = new IE(BuildUrl("Account", "New")))
            {
                browser.TextField(Find.ById("registration_userName")).TypeText("andypike");
                browser.TextField(Find.ById("registration_password")).TypeText("123456");
                browser.TextField(Find.ById("registration_email")).TypeText("someone@somewhere.com");
                browser.TextField(Find.ById("recaptcha_response_field")).TypeText("random words");
                browser.Button(Find.ById("register")).Click();

                Assert.That(browser.ContainsText("You failed the human test! Try typing the two words again."), Is.True);
            }
        }
    }
}